import { Service } from 'egg';
import { Op } from 'sequelize';

/**
 * 后台用户接口
 */
export default class AdminUserService extends Service {
  /**
   * 根据用户名或者邮箱查找用户
   * @param nameOrEmail - 登录名-用户名或者邮箱
   */
  public async findByLogin(nameOrEmail: string) {
    return await this.ctx.model.AdminUser.findOne({
      where: {
        [Op.or]: {
          username: nameOrEmail,
          email: nameOrEmail
        }
      }
      // include: [{ model: this.sequelize.models.adminRole, attributes: ['id', 'sign'], as: 'role' }]
    });
  }
}
